/* eslint valid-jsdoc: "off" */

'use strict';

/**
 * @param {Egg.EggAppInfo} appInfo app info
 */
module.exports = appInfo => {
  /**
   * built-in config
   * @type {Egg.EggAppConfig}
   **/
  const config = exports = {};

  // config/config.${env}.js
  exports.mysql = {
  // 单数据库信息配置
    client: {
    // host
      host: '123.57.158.140',
      // 端口号
      port: '3306',
      // 用户名
      user: 'root',
      // 密码
      password: '123456',
      // 数据库名
      database: 'inurse',
      timezone: '+08:00', // 由于ORM用的是UTC时间，这里必须加上东八区，否则取出来的时间相差8小时
      dialectOptions: {// 让读取date类型数据时返回字符串而不是UTC时间
        charset: 'utf8mb4',
        collate: 'utf8mb4_unicode_ci',
        supportBigNumbers: true,
        bigNumbersString: true,
        // dateString: true,
        // typeCast(field, next) {
        //   if (field.type === 'DATETIME') {
        //     return field.string();
        //   }
        //   return next();
        // },
      },
      define: {
        freezeTableName: true,
      },
    },
    // 是否加载到 app 上，默认开启
    app: true,
    // 是否加载到 agent 上，默认关闭
    agent: false,

    logger: {
      dir: 'D:/My_NoticeApp',
      level: 'DEBUG',
      outputJSON: true,
      encoding: 'UTF-8',
    },
  };

  // config.multipart = {
  //   mode: 'file',
  // };

  config.sequelize = {
    dialect: 'mysql',
    host: '123.57.158.140',
    port: '3306',
    username: 'root',
    password: '123456',
    database: 'inurse',
  };

  config.jwt = {
    secret: '123456', // 自定义 token 的加密条件字符串
  };

  // config.logger: {
  //   dir:'D:/My_NoticeApp',
  //   level:'DEBUG',
  //   outputJSON:true,
  //   encoding:'UTF-8'
  // },

  /** ****** 允许跨域访问,关闭csrf认证 /config.default.js ********/
  exports.security = {
    csrf: {
      enable: false,
      ignoreJSON: true,
    },
    domainWhiteList: [ 'http://localhost:7001' ], // 允许访问接口的白名单
  };

  config.cors = {
    origin: '*',
    allowMethods: 'GET,HEAD,PUT,POST,DELETE,PATCH',
  };

  // use for cookie sign key, should change to your own and keep security
  config.keys = appInfo.name + '_1584345531593_7692';

  // add your middleware config here
  config.middleware = [];

  // 配置ejs模板引擎
  config.view = {
    mapping: {
      '.html': 'ejs',
    },
  };

  // add your user config here
  const userConfig = {
    // myAppName: 'egg',
  };

  return {
    ...config,
    ...userConfig,
  };


};
